package com.hzw.saas.api.hpc.bo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.hzw.saas.api.hpc.enums.HpcContractStatus;
import com.hzw.saas.common.config.bo.BaseBO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @Description
 * @Date 2021/7/16 1:02 下午
 * @Created by sonam
 */
@Data
@Accessors(chain = true)
public class HpcContractBO extends BaseBO {

    @ApiModelProperty(value = "HPC账号ID")
    private String contractName;

    @ApiModelProperty(value = "合同编号")
    private String contractNo;

    @ApiModelProperty(value = "用户ID")
    private String userId;

    @ApiModelProperty(value = "用户名")
    private String userName;

    @ApiModelProperty(value = "用户真实姓名")
    private String realName;

    @ApiModelProperty(value = "手机号码")
    private String phoneNo;

    @ApiModelProperty(value = "用户邮箱")
    private String email;

    @ApiModelProperty(value = "合同金额")
    private Double contractAmount;

    @ApiModelProperty(value = "购买的算力")
    private Double coreTime;

    @ApiModelProperty(value = "无限算力，1｜无限，0｜有限")
    private Integer isInfinite;

    @ApiModelProperty(value = "到期时间")
    private Date expireTime;

    @ApiModelProperty(value = "HPC账号ID")
    private String hpcAccountId;

    @ApiModelProperty(value = "HPC账号名称")
    private String hpcAccount;

    @ApiModelProperty(value = "HPC-RECORD-ID")
    private String hpcAccountRecordId;

    @ApiModelProperty(value = "登记时间")
    private Date busTime;

    @ApiModelProperty(value = "合同类型", notes = "合同类型，1-正式合同，2-试用合同")
    private Integer contractType;

    @ApiModelProperty(value = "合同供应商类型")
    private String providerCode;

    public String getStatusText() {
        if(DateUtil.compare(expireTime, DateUtil.date()) < 0 && StrUtil.isBlank(hpcAccountId)) {
            return HpcContractStatus.FAILS_PERFORM.text(); // 合同到期，未绑定HPC账号
        } else if(StrUtil.isBlank(hpcAccountId)) {
            return HpcContractStatus.FAILS_PERFORM.text(); // 未履行
        } else if(StrUtil.isNotBlank(hpcAccountId) && DateUtil.compare(expireTime, DateUtil.date()) > 0) {
            return HpcContractStatus.PERFORM.text(); // 履行中
        } else if(StrUtil.isNotBlank(hpcAccountId) && DateUtil.compare(expireTime, DateUtil.date()) <= 0) {
            return HpcContractStatus.PERFORM_FINISHED.text(); // 履行完毕
        }
        return "NULL";
    }

    public int getStatusCode() {
        return HpcContractStatus.instance(getStatusText()).value();
    }

}
